Repository Public
1import { nextStageFor, OpError, runStage } from "@/lib/studio-ops";2import { isUuid, out, studio } from "@/lib/studio-api";34/** POST /api/studio/projects/:id/generate — run `stage` (or the next one). Repeating the call while it runs returns the same run. */5export async function POST(req: Request, ctx: { params: Promise<{ id: string }> }) {6 const { id } = await ctx.params;7 return studio(req, "editor", async (user, body) => {8 if (!isUuid(id)) throw new OpError("Project not found", 404);9 const stage = typeof body.stage === "string" ? body.stage : await nextStageFor(id);10 if (!stage) throw new OpError("No stage left to run: the film is waiting for approval or already published", 409);11 const r = await runStage(user, id, stage, { fresh: body.fresh === true });12 return out({ projectId: id, stage, jobId: r.runId, duplicate: r.duplicate }, 202);13 });14}15